import aircraftImg from '@/assets/img/gotop.png';
import { useEffect, useState } from 'react';
import { useModel } from 'umi';
import './index.less';

export default function Aircraft() {
  const { headerAteFlag, setHeaderAteFlag } = useModel('homeModel');
  const [clickFlag, setclickFlag] = useState(false);

  function onIcon() {
    setclickFlag(true);
  }

  useEffect(() => {
    if (clickFlag === true) {
      document.documentElement.scrollTop = 0;
      setTimeout(() => {
        setclickFlag(false);
      }, 1000);
    }
  }, [clickFlag]);

  return (
    <>
      {clickFlag ? (
        <div className={`aircraft-cpm aircraft-cpm-close`}>
          <img src={aircraftImg} alt="aircraftImg" onClick={onIcon} />
        </div>
      ) : (
        !headerAteFlag && (
          <div className={`aircraft-cpm`}>
            <img src={aircraftImg} alt="aircraftImg" onClick={onIcon} />
          </div>
        )
      )}
 
    </>
  );
}
